/*
 * Copyright (C) 2001-2005 Pleasant nightmare studio
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.pleasantnightmare.noraxidium.collision;

import org.apache.log4j.Logger;
import org.lwjgl.util.Rectangle;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.pleasantnightmare.noraxidium.model.GameObject;
import org.pleasantnightmare.noraxidium.model.LevelMap;
import org.pleasantnightmare.noraxidium.model.Rendered;

/**
 * Renders collision rects
 *
 * @author deus
 * @version 1.0
 * @since Jul 9, 2010 1:48:27 PM
 */
public class CollisionRenderer implements Rendered {
  private static final Logger LOGGER = Logger.getLogger(CollisionRenderer.class);
  private LevelMap levelMap;

  public CollisionRenderer() {
  }

  public CollisionRenderer(LevelMap levelMap) {
    this.levelMap = levelMap;
  }

  public void setLevelMap(LevelMap levelMap) {
    this.levelMap = levelMap;
  }

  @Override public void render(Graphics g) {
    if (levelMap == null)
      return;

    g.setColor(Color.red);
    for (RectBound rectBound : levelMap.getSolidCollision()) {
      Rectangle rect = rectBound.getRect();
      g.drawRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    }

    g.setColor(Color.yellow);
    for (GameObject gameObject : levelMap.getObjects()) {
      Rectangle rect = ((RectBound) gameObject.getCollisionBound()).getRect();
      g.drawRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    }
  }
}
